{php include wl_template('common/header');}

<ul class="nav nav-tabs">
	<li {if $op == 'hx_entry' }class="active"{/if}>
        <a href="{php echo web_url('application/bdelete/hx_entry')}">关键词设置</a>
    </li>
    <li {if $op == 'store' && $opp == 'display'} class="active"{/if}>
        <a href="{php echo web_url('application/bdelete/store')}">核销门店管理</a>
    </li>
    {if $opp == 'post'}
    <li {if $op == 'store' && $opp == 'post'} class="active"{/if}>
        <a href="{php echo web_url('application/bdelete/store',array('opp'=>'post'))}">编辑门店</a>
    </li>
    {/if}
	<li {if $op == 'saler' && $opp == 'display'} class="active"{/if}>
        <a href="{php echo web_url('application/bdelete/saler')}">核销员管理</a>
    </li>
    {if $op == 'saler' && $opp == 'post'}
    <li {if $op == 'saler' && $opp == 'post'} class="active"{/if}>
        <a href="{php echo web_url('application/bdelete/saler',array('opp'=>'post'))}">编辑核销员</a>
    </li>
    {/if}
</ul>

{if $op == 'hx_entry'}
<div class="main">
    <form id="dataform" action="" method="post" class="form-horizontal form">
        <div class="panel panel-default">
            <div class="panel-heading">
                核销设置
            </div>
            <div class="panel-body">
                    <div class="form-group">
                       <label class="col-xs-12 col-sm-3 col-md-2 control-label">核销关键字</label>
                       <div class="col-sm-9 col-xs-12">
                           <input type="text" name="keyword" class="form-control" value="{$set['content']}" />
                           <span class='help-block'>店员核销使用，如果不填写默认为核销，使用方法: 回复关键词后系统会提示输入核销码</span>
                       </div>
                   </div>
                   <div class="form-group">
                           <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                           <div class="col-sm-9 col-xs-12">
                                 <input type="submit" name="keysubmit"  value="保存设置" class="btn btn-primary"/>
                                 <input type="hidden" name="token" value="{$_W['token']}" />
                           </div>
                    </div>
            </div>
        </div>
    </form>
</div>
{/if}
{if $op == 'store'}
	{if $opp=='post'}
		<div class="main">
		    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
		        <input type="hidden" name="id" value="{$item['id']}" />
		        <div class='panel panel-default'>
		            <div class='panel-heading'>
		                核销门店设置
		            </div>
		            <div class='panel-body'>
		            	<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>所属商家</label>
							<div class="col-sm-9 col-xs-12">
								<select name="merchantid" class="form-control">
									<option value="" {if empty($item['merchantid'])}selected="selected"{/if}>{$_W['account']['name']}</option>
								{loop $merchants $row}
						            <option value="{$row['id']}" {if $item['merchantid']==$row['id']}selected="selected"{/if}>{$row['name']}</option>
								{/loop}}
						        </select>
							</div>
						</div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 门店名称</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type="text" name="storename" id="hexiaoname" class="form-control" value="{$item['storename']}" />
		                    </div>
		                </div>
		               <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店地址</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type="text" name="address" id="address" class="form-control" value="{$item['address']}" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店电话</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type="text" name="tel" class="form-control" value="{$item['tel']}" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店位置</label>
		                    <div class="col-sm-9 col-xs-12">
		                        {php echo tpl_form_field_coordinate('map',array('lng'=>$item['lng'],'lat'=>$item['lat']))}
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class='radio-inline'>
		                            <input type='radio' name='qiyongstatus' value=1 {if $item['status']==1}checked{/if} /> 启用
		                        </label>
		                        <label class='radio-inline'>
		                            <input type='radio' name='qiyongstatus' value=0 {if $item['status']==0}checked{/if} /> 禁用
		                        </label>
		                    </div>
		                </div>
		                      <div class="form-group"></div>
		            <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		                    <div class="col-sm-9 col-xs-12">
		                    		<input type="hidden" name="op" value="{$op}" />
		                            <input type="submit" name="storesubmit" value="提交" class="btn btn-primary col-lg-1"  />
		                            <input type="hidden" name="token" value="{$_W['token']}" />
		                    </div>
		            </div>
		            </div>
		        </div>
		     
		    </form>
		</div>
		<script language='javascript'>
	    $('form').submit(function(){
	        if($(':input[name=storename]').isEmpty()){
	            Tip.focus($(':input[name=storename]'),'请输入门店名称!');
	            return false;
	        }
	        return true;
	    })
	    </script>
	{elseif $opp == 'display'}
				<div class="main">
				     <div class='panel panel-default'>
				            <div class='panel-heading'>
				                核销门店设置
				            </div>
				         <div class='panel-body'>
				            <table class="table">
				                <thead>
				                    <tr>
				                    	<!--<th>所属商家</th>-->
				                        <th>门店名称</th>
				                        <th>门店地址</th>
				                        <th>门店电话</th>
				                        <th>状态</th>
				                        <th>操作</th>
				                    </tr>
				                </thead>
				                <tbody>
				                    {loop $list $row}
				                    <tr>
				                    	<!--<td>{if $row['merchant']['name']}{$row['merchant']['name']}{else}{$_W['account']['name']}{/if}</td>
				     -->                   <td>{$row['storename']}</td>
				                        <td>{$row['address']}</td>
				                           <td>{$row['tel']}</td>                            
				                                                  
				                                 <td>
				                                    {if $row['status']==1}
				                                    <span class='label label-success'>启用</span>
				                                    {else}
				                                    <span class='label label-danger'>禁用</span>
				                                    {/if}
				                                </td>
				                        <td>
				                         <a class='btn btn-default' href="{php echo web_url('application/bdelete/store', array('opp'=>'post','id' => $row['id']))}"><i class='fa fa-edit'></i></a>
				                         <a class='btn btn-default'  href="{php echo web_url('application/bdelete/store', array('opp'=>'delete','id' => $row['id']))}" onclick="return confirm('确认删除此门店吗？');return false;"><i class='fa fa-remove'></i></a></td>
				                    </tr>
				                    {/loop}
				                </tbody>
				            </table>
				         </div>
				           <div class='panel-footer'>
				                 <a class='btn btn-default' href="{php echo web_url('application/bdelete/store', array('opp'=>'post'))}"><i class="fa fa-plus"></i> 添加新门店</a>
				         </div>
				     </div>
			</div>
	{/if}
{/if}
{if $op=='saler'}
	{if $opp == 'post'}
		<div class="main">
		    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
		        <div class='panel panel-default'>
		            <div class='panel-heading'>
		                核销员设置
		            </div>
		            <div class='panel-body'>
		               <div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>所属商家{$item['merchantid']}</label>
							<div class="col-sm-9 col-xs-12">
								<select name="merchantid" class="form-control">
									<option value="" {if empty($saler['merchantid'])}selected="selected"{/if}>{$_W['account']['name']}</option>
								{loop $merchants $row}
						            <option value="{$row['id']}" {if $saler['merchantid']==$row['id']}selected="selected"{/if}>{$row['name']}</option>
								{/loop}}
						        </select>
							</div>
						</div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 选择核销员</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type='hidden' id='openid' name='openid' value="{$saler['openid']}" />
		                        <div class='input-group'>
		                            <input type="text" name="saler" maxlength="30" value="{if !empty($saler)}{$saler['nickname']}{/if}" id="saler" class="form-control" readonly />
		                            <div class='input-group-btn'>
		                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus').modal();">选择核销员</button>
		                            </div>
		                        </div>
		                        {if !empty($saler)}
		                        <span class='help-block'><img style="width:100px;height:100px;border:1px solid #ccc;padding:1px" src="{$saler['avatar']}" id="avatar" /></span>
		                        {/if}
		                        <div id="modal-module-menus"  class="modal fade" tabindex="-1">
		                            <div class="modal-dialog" style='width: 660px;'>
		                                <div class="modal-content">
		                                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择核销员</h3></div>
		                                    <div class="modal-body" >
		                                        <div class="row">
		                                            <div class="input-group">
		                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd" placeholder="请输入粉丝昵称" />
		                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>
		                                            </div>
		                                        </div>
		                                        <div id="module-menus" style="padding-top:5px;"></div>
		                                    </div>
		                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
		                                </div>
		                            </div>
		                        </div>
		                    </div>
		                </div>

		                 <div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">核销门店选择</label>
							<div class="col-sm-9 col-xs-12 chks">
								<div class='input-group'>
									<input type="text" name="saler" maxlength="30" value="{loop $salers $saler} {$saler['nickname']}; {/loop}" id="saler" class="form-control" readonly />
									<div class='input-group-btn'>
										<button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus2').modal();">选择门店</button>
									</div>
								</div>
					
								<div style="margin-top:.5em;" class="input-group multi-audio-details clear-fix" id='stores'>
									{loop $stores $store}
									<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="{$store['id']}">
										<div class="input-group">
											<input type="hidden" value="{$store['id']}" name="storeids[]">
											<input type="text" value="{$store['storename']}" readonly="" class="form-control">
											<div class="input-group-btn">
												<button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button>
											</div>
										</div>
									</div>
									{/loop}
								</div>
								<span class='help-block'>如果不选择门店，则此核销员为全局核销员，所有门店的均可核销</span>					
								<div id="modal-module-menus2" class="modal fade" tabindex="-1">
									<div class="modal-dialog" style='width: 660px;'>
										<div class="modal-content">
											<div class="modal-header">
												<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
												<h3>选择门店</h3></div>
											<div class="modal-body">
												<div class="row">
													<div class="input-group">
														<input type="text" class="form-control" name="keyword" value="" id="search-kwd2" placeholder="请输入门店名称" />
														<span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_stores();">搜索</button></span>
													</div>
												</div>
												<div id="module-menus2" style="padding-top:5px;"></div>
											</div>
											<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
										</div>
									</div>
								</div>
							</div>
						</div>
		              
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class='radio-inline'>
		                            <input type='radio' name='salerstatus' value=1 {if $saler['status']==1}checked{/if} /> 启用
		                        </label>
		                        <label class='radio-inline'>
		                            <input type='radio' name='salerstatus' value=0 {if $saler['status']==0}checked{/if} /> 禁用
		                        </label>
		                    </div>
		                </div>
		                
		                   <div class="form-group"></div>
		            <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		                    <div class="col-sm-9 col-xs-12">
		                    		<input type="hidden" name="salerid" value="{$id}" />
		                    		<input type="hidden" name="op" value="{$op}" />
		                            <input type="submit" name="salersubmit" value="提交" class="btn btn-primary col-lg-1"  />
		                            <input type="hidden" name="token" value="{$_W['token']}" />
		                    </div>
		            </div>
		            </div>
		        </div>
		    </form>
		</div>
		<script language='javascript'>
		    $('form').submit(function () {
		        if ($(':input[name=saler]').isEmpty()) {
		            Tip.focus($(':input[name=saler]'), '请选择核销员!');
		            return false;
		        }
		        return true;
		    })
		</script>
	{elseif $opp == 'display'}
		<form action="" method="post" onsubmit="return formcheck(this)">
		    <div class='panel panel-default'>
		        <div class='panel-heading'>
		          	  核销员管理
		        </div>
		        <div class='panel-body'>
		            <table class="table">
		                <thead>
		                    <tr>
		               <!--     	<th>所属商家</th>-->
		                        <th>核销员</th>
		                        <th>所属门店</th>
		                        <th>状态</th>
		                        <th>操作</th>
		                    </tr>
		                </thead>
		                <tbody>
		                    {loop $list $row}
		                    <tr>
		                    <!--	<td>{if $row['merchant']['name']}{$row['merchant']['name']}{else}{$_W['account']['name']}{/if}</td>
		                     -->   <td style="text-align:left;"><img src="{$row['avatar']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc" id="avatar" /> {$row['nickname']}</td>
		                        <td>{if empty($row['storename'])}全店核销{else}{$row['storename']}{/if}</td>
		                        <td>
		                            {if $row['status']==1}
		                            <span class='label label-success'>启用</span>
		                            {else}
		                            <span class='label label-danger'>禁用</span>
		                            {/if}
		                        </td>
		                        <td>
		                            <a class='btn btn-default' href="{php echo web_url('application/bdelete/saler', array('opp'=>'post','id' => $row['id']))}"><i class='fa fa-edit'></i></a>
		                            <a class='btn btn-default'  href="{php echo web_url('application/bdelete/saler', array('opp'=>'post', 'id' => $row['id']))}" onclick="return confirm('确认删除此核销员吗？');
		                                    return false;"><i class='fa fa-remove'></i></a>
		                           </td>
		                    </tr>
		                    {/loop}
		                </tbody>
		            </table>
		        </div>
		        <div class='panel-footer'>
		            <a class='btn btn-default' href="{php echo web_url('application/bdelete/saler', array('opp'=>'post'))}"><i class="fa fa-plus"></i> 添加新核销员</a>
		        </div>
		    </div>
		</form>
	{/if}

	<script language='javascript'>
	    function search_members() {
           	if( $.trim($('#search-kwd').val())==''){
                Tip.focus('#search-kwd','请输入关键词');
                return;
            }

			$("#module-menus").html("正在搜索....")
			$.get('{php echo web_url('application/bdelete/display',array('op'=>'selectsaler'))}', {
				keyword: $.trim($('#search-kwd').val())
			}, function(dat){
				$('#module-menus').html(dat);
			});
		}
		function select_member(o) {
			$("#openid").val(o.openid);
			$("#saler").val(o.nickname);
			$("#avatar").attr('src', o.avatar);
			$(".close").click();
		}
	    function search_stores() {
			$("#module-menus2").html("正在搜索....")
			$.get('{php echo web_url('application/bdelete/display',array('op'=>'selectstore'))}', {
				keyword: $.trim($('#search-kwd2').val())
			}, function(dat){
				$('#module-menus2').html(dat);
			});
		}
		function remove_store(obj){
	        var storeid = $(obj).closest('.multi-audio-item').attr('storeid');
	        	$('.multi-audio-item[storeid="' + storeid +'"]').remove();
		    }
		function select_store(o) {
            if($('.multi-audio-item[storeid="' + o.id +'"]').length>0){
                return;
            }
            var html ='<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="' + o.id +'">';
                html+='<div class="input-group">';
                html+='<input type="hidden" value="' + o.id +'" name="storeids[]">';
                html+='<input type="text" value="' + o.storename +'" readonly="" class="form-control">';
                html+='<div class="input-group-btn"><button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button></div>';
             	html+='</div></div>';
                $('#stores').append(html);
		}
	</script>
{/if}
{php include wl_template('common/footer');}